<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates a new SimpleXMLElement object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="simplexmlelement.children.html">SimpleXMLElement::children</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="simplexmlelement.count.html">SimpleXMLElement::count</a></div>
 <div class="up"><a href="class.simplexmlelement.html">SimpleXMLElement</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="simplexmlelement.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SimpleXMLElement::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.0.1)</p><p class="refpurpose"><span class="refname">SimpleXMLElement::__construct</span> &mdash; <span class="dc-title">
   Creates a new SimpleXMLElement object
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-simplexmlelement.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>SimpleXMLElement::__construct()</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$data_is_url</code><span class="initializer"> = false</span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$ns</code><span class="initializer"> = &quot;&quot;</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_prefix</code><span class="initializer"> = false</span></span>
  ]]]] )</div>

  <p class="para rdfs-comment">
   Creates a new <a href="class.simplexmlelement.html" class="classname">SimpleXMLElement</a> object.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-simplexmlelement.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">data</code></em></dt>

     <dd>

      <p class="para">
       A well-formed XML string or the path or URL to an XML document if 
       <em><code class="parameter">data_is_url</code></em> is <strong><code>TRUE</code></strong>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">options</code></em></dt>

     <dd>

      <p class="para">
       Optionally used to specify <a href="libxml.constants.html" class="link">additional
       Libxml parameters</a>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">data_is_url</code></em></dt>

     <dd>

      <p class="para">
       By default, <em><code class="parameter">data_is_url</code></em> is <strong><code>FALSE</code></strong>. Use <strong><code>TRUE</code></strong> to
       specify that <em><code class="parameter">data</code></em> is a path or URL to an XML 
       document instead of <span class="type"><a href="language.types.string.html" class="type string">string</a></span> data.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">ns</code></em></dt>

     <dd>

      <p class="para">
       Namespace prefix or URI.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">is_prefix</code></em></dt>

     <dd>

      <p class="para">
       <strong><code>TRUE</code></strong> if <em><code class="parameter">ns</code></em> is a prefix, <strong><code>FALSE</code></strong> if it&#039;s a URI;
       defaults to <strong><code>FALSE</code></strong>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-simplexmlelement.construct-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a <span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span> object representing 
   <em><code class="parameter">data</code></em>.
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-simplexmlelement.construct-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Produces an <strong><code>E_WARNING</code></strong> error message for each error
   found in the XML data and additionally throws an <a href="class.exception.html" class="classname">Exception</a> if the XML data
   could not be parsed.
  </p>
  <div class="tip"><strong class="tip">Tip</strong>
   <p class="para">
    Use <span class="function"><a href="function.libxml-use-internal-errors.html" class="function">libxml_use_internal_errors()</a></span> to suppress all XML
    errors, and <span class="function"><a href="function.libxml-get-errors.html" class="function">libxml_get_errors()</a></span> to iterate over them
    afterwards.
   </p>
  </div>
 </div>

 
 <div class="refsect1 examples" id="refsect1-simplexmlelement.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <p class="para">
     Listed examples may include <em>example.php</em>,
     which refers to the XML string found in the first example
     of the <a href="simplexml.examples-basic.html" class="link">basic usage</a> guide.
    </p>
   </p></blockquote>
   <div class="example" id="example-5384">
    <p><strong>Example #1 Create a SimpleXMLElement object</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">'example.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$sxe&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">title</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
PHP: Behind the Parser
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5385">
    <p><strong>Example #2 Create a SimpleXMLElement object from a URL</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$sxe&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://example.org/document.xml'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">asXML</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-simplexmlelement.construct-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.2.0</td>
       <td>Added the <em><code class="parameter">ns</code></em> and <em><code class="parameter">is_prefix</code></em> parameters.</td>
      </tr>

      <tr>
       <td>5.1.2</td>
       <td>Added the <em><code class="parameter">options</code></em> and <em><code class="parameter">data_is_url</code></em> parameters.</td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-simplexmlelement.construct-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="simplexml.examples-basic.html" class="xref">Basic SimpleXML usage</a></li>
    <li class="member"><span class="function"><a href="function.simplexml-load-string.html" class="function" rel="rdfs-seeAlso">simplexml_load_string()</a> - Interprets a string of XML into an object</span></li>
    <li class="member"><span class="function"><a href="function.simplexml-load-file.html" class="function" rel="rdfs-seeAlso">simplexml_load_file()</a> - Interprets an XML file into an object</span></li>
    <li class="member"><a href="simplexml.examples-errors.html" class="xref">Dealing with XML errors</a></li>
    <li class="member"><span class="function"><a href="function.libxml-use-internal-errors.html" class="function" rel="rdfs-seeAlso">libxml_use_internal_errors()</a> - Disable libxml errors and allow user to fetch error information as needed</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="simplexmlelement.children.html">SimpleXMLElement::children</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="simplexmlelement.count.html">SimpleXMLElement::count</a></div>
 <div class="up"><a href="class.simplexmlelement.html">SimpleXMLElement</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
